<div class="panel panel-default panel-intro">
    <div class="panel-heading">
        <div class="panel-lead"><em>小程序配置</em></div>

    </div>

    <div class="panel-body">
        <div id="myTabContent" class="tab-content">
            <div class="tab-pane fade active in" id="one">
                <div class="widget-body no-padding">
                    <form id="one-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
                        <table class="table table-striped table-config">
                            <tbody>
                            <tr style="display: none;">
                                <td>APP appid</td>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-8 col-xs-12">
                                            <input type="text" name="row[wechat][appid]" value="{$addon['config'][1]['value']['appid']|default=''}" class="form-control" data-rule="" data-tip="APP应用中支付时使用"/>
                                        </div>
                                        <div class="col-sm-4"></div>
                                    </div>
                                </td>
                            </tr>
                            <tr style="display: none;">
                                <td>公众号的app_id</td>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-8 col-xs-12">
                                            <input type="text" name="row[wechat][app_id]" value="{$addon['config'][1]['value']['app_id']|default=''}" class="form-control" data-rule="" data-tip="公众号支付必须"/>
                                        </div>
                                        <div class="col-sm-4"></div>
                                    </div>
                                </td>
                            </tr>
                            <tr style="display: none;">
                                <td>公众号的app_secret</td>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-8 col-xs-12">
                                            <input type="text" name="row[wechat][app_secret]" value="{$addon['config'][1]['value']['app_secret']|default=''}" class="form-control" data-rule="" data-tip="仅在需要获取Openid时使用，一般情况下为空"/>
                                        </div>
                                        <div class="col-sm-4"></div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td width="200">小程序的app_id</td>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-8 col-xs-12">
                                            <input type="text" name="row[wechat][miniapp_id]" value="{$addon['config'][1]['value']['miniapp_id']|default=''}" class="form-control" data-rule="" data-tip="仅在小程序支付时使用"/>
                                        </div>
                                        <div class="col-sm-4"></div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>微信支付商户号ID</td>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-8 col-xs-12">
                                            <input type="text" name="row[wechat][mch_id]" value="{$addon['config'][1]['value']['mch_id']|default=''}" class="form-control" data-rule="" data-tip=""/>
                                        </div>
                                        <div class="col-sm-4"></div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>微信支付商户的密钥</td>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-8 col-xs-12">
                                            <input type="text" name="row[wechat][key]" value="{$addon['config'][1]['value']['key']|default=''}" class="form-control" data-rule="" data-tip=""/>
                                        </div>
                                        <div class="col-sm-4"></div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>支付模式</td>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-8 col-xs-12">
                                            {:Form::radios('row[wechat][mode]',['normal'=>'正式环境','dev'=>'沙箱环境','service'=>'服务商模式'],$addon['config'][1]['value']['mode']??'normal')}
                                        </div>
                                        <div class="col-sm-4"></div>
                                    </div>
                                </td>
                            </tr>
                            <tr data-type="service" class="{:$addon['config'][1]['value']['mode']!='service'?'hidden':''}">
                                <td>子商户商户号ID</td>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-8 col-xs-12">
                                            <input type="text" name="row[wechat][sub_mch_id]" value="{$addon['config'][1]['value']['sub_mch_id']|default=''}" class="form-control" data-rule="" data-tip="如果未用到子商户，请勿填写"/>
                                        </div>
                                        <div class="col-sm-4"></div>
                                    </div>
                                </td>
                            </tr>
                            <tr data-type="service" class="{:$addon['config'][1]['value']['mode']!='service'?'hidden':''}">
                                <td>子商户 APP appid</td>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-8 col-xs-12">
                                            <input type="text" name="row[wechat][sub_appid]" value="{$addon['config'][1]['value']['sub_appid']|default=''}" class="form-control" data-rule="" data-tip="如果未用到子商户，请勿填写"/>
                                        </div>
                                        <div class="col-sm-4"></div>
                                    </div>
                                </td>
                            </tr>
                            <tr data-type="service" class="{:$addon['config'][1]['value']['mode']!='service'?'hidden':''}">
                                <td>子商户公众号的appid</td>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-8 col-xs-12">
                                            <input type="text" name="row[wechat][sub_app_id]" value="{$addon['config'][1]['value']['sub_app_id']|default=''}" class="form-control" data-rule="" data-tip="如果未用到子商户，请勿填写"/>
                                        </div>
                                        <div class="col-sm-4"></div>
                                    </div>
                                </td>
                            </tr>
                            <tr data-type="service" class="{:$addon['config'][1]['value']['mode']!='service'?'hidden':''}">
                                <td>子商户小程序的appid</td>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-8 col-xs-12">
                                            <input type="text" name="row[wechat][sub_miniapp_id]" value="{$addon['config'][1]['value']['sub_miniapp_id']|default=''}" class="form-control" data-rule="" data-tip="如果未用到子商户，请勿填写"/>
                                        </div>
                                        <div class="col-sm-4"></div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>回调通知地址</td>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-8 col-xs-12">
                                            <input type="text" name="row[wechat][notify_url]" value="{$item.value.notify_url|default=''}" class="form-control" data-rule="" data-tip="请勿随意修改，实际以逻辑代码中请求的为准"/>
                                        </div>
                                        <div class="col-sm-4"></div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>微信支付API证书cert</td>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-8 col-xs-12">
                                            <div class="input-group">
                                                <input id="c-cert_client" class="form-control" size="50" name="row[wechat][cert_client]" type="text" value="{$addon['config'][1]['value']['cert_client']|htmlentities}" data-tip="可选, 仅在退款、红包等情况时需要用到">
                                                <div class="input-group-addon no-border no-padding">
                                                    <span><button type="button" id="faupload-cert_client" class="btn btn-danger faupload" data-url="epay/upload" data-multipart='{"certname":"cert_client"}' data-mimetype="pem" data-input-id="c-cert_client" data-multiple="false"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
                                                </div>
                                                <span class="msg-box n-right" for="c-cert_client"></span>
                                            </div>
                                            <div style="margin-top:5px;"><a href="https://pay.weixin.qq.com" target="_blank"><i class="fa fa-question-circle"></i> 如何获取微信支付API证书?</a></div>
                                        </div>
                                        <div class="col-sm-4"></div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td>微信支付API证书key</td>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-8 col-xs-12">
                                            <div class="input-group">
                                                <input id="c-cert_key" class="form-control" size="50" name="row[wechat][cert_key]" type="text" value="{$addon['config'][1]['value']['cert_key']|htmlentities}" data-tip="可选, 仅在退款、红包等情况时需要用到">
                                                <div class="input-group-addon no-border no-padding">
                                                    <span><button type="button" id="faupload-cert_key" class="btn btn-danger faupload" data-url="epay/upload" data-multipart='{"certname":"cert_key"}' data-mimetype="pem" data-input-id="c-cert_key" data-multiple="false"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
                                                </div>
                                                <span class="msg-box n-right" for="c-cert_key"></span>
                                            </div>
                                            <div style="margin-top:5px;"><a href="https://pay.weixin.qq.com" target="_blank"><i class="fa fa-question-circle"></i> 如何获取微信支付API证书?</a></div>
                                        </div>
                                        <div class="col-sm-4"></div>
                                    </div>
                                </td>
                            </tr>

                            <tr>
                                <td>记录日志</td>
                                <td>
                                    <div class="row">
                                        <div class="col-sm-8 col-xs-12">
                                            {:Form::radios('row[wechat][log]',['1'=>'开启','0'=>'关闭'],$addon['config'][1]['value']['log'])}
                                        </div>
                                        <div class="col-sm-4"></div>
                                    </div>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <div class="form-group layer-footer">
                            <label class="control-label col-xs-12 col-sm-2"></label>
                            <div class="col-xs-12 col-sm-8">
                                <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
                                <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
                            </div>
                        </div>
                    </form>

                </div>
            </div>

        </div>
    </div>
</div>

<script>
    document.querySelectorAll("input[name='row[wechat][mode]']").forEach(function (i, j) {

        i.addEventListener("click", function () {
            document.querySelectorAll("table tr[data-type]").forEach(function (m, n) {
                m.classList.add("hidden");
            });
            document.querySelectorAll("table tr[data-type='" + this.value + "']").forEach(function (m, n) {
                m.classList.remove("hidden");
            });
        });
    });
</script>
